package com.company.book_store.web.servlet;

import com.alibaba.fastjson.JSON;
import com.company.book_store.pojo.Book;
import com.company.book_store.pojo.Bookinfo;
import com.company.book_store.pojo.User;
import com.company.book_store.service.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/selfInfo")
public class selfInfo extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String account = req.getParameter("account");
        Ibookinfoservice info  = new Bookinfoservice();
        List<Bookinfo> list = info.selectByusername(account);
        Map<Object,Object>map = new HashMap<>();
        Iuserservice iuserservice = new UserserviceImpl();
        User user = iuserservice.selectByaccount(account);
        map.put("username",user.getName());
        map.put("list",list);
        String jsonStr = JSON.toJSONString(map);
        PrintWriter out = resp.getWriter();
        out.write(jsonStr);
    }
}
